package com.label.Web;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.label.Config.Logger.LogAnnotation;
import com.label.Model.Common.ResponseBean;
import com.label.Model.Do.SemeWarn;
import com.label.Model.Query.HelpRecordQuery;
import com.label.Model.Query.UserQuery;
import com.label.Model.Query.WarnQuesQuery;
import com.label.Model.Query.WarningQuery;
import com.label.Model.Vo.SemeWarnVo;
import com.label.Service.WarningService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Nullable;
import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/warning")
public class WarningController {

    @Resource
    private WarningService warningService;

    @RequestMapping("/stuSearch")
    @LogAnnotation(module = "预警模块", operator = "累计搜索")
    public ResponseBean stuSearch(@RequestBody WarningQuery warningQuery) {
        try{
            String data=warningService.warningStuSearch(warningQuery);
            return new ResponseBean(HttpStatus.OK.value(), "成功",data);
        }catch (Exception e){
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR.value(), "错误",null);
        }
    }

    @RequestMapping("/warningStuDetail")
    @LogAnnotation(module = "预警模块", operator = "学生信息详情")
    public ResponseBean warningStuDetail(@RequestBody WarningQuery warningQuery) {
        try{
            String data=warningService.warningStuDetail(warningQuery);
            return new ResponseBean(HttpStatus.OK.value(), "成功",data);
        }catch (Exception e){
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR.value(), "错误",null);
        }
    }

    @RequestMapping("/questWarn")
    @LogAnnotation(module = "预警模块", operator = "学生提交问题详情")
    public ResponseBean questWarn(@RequestBody WarnQuesQuery warnQuesQuery) {
        try{
            warningService.questWarn(warnQuesQuery);
            return new ResponseBean(HttpStatus.OK.value(), "成功",true);
        }catch (Exception e){
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR.value(), "错误",null);
        }
    }

    @RequestMapping("/semeWarn")
    @LogAnnotation(module = "预警模块", operator = "学期预警详情")
    public ResponseBean semeWarn(@RequestParam String year,@RequestParam String seam) {
        try{
            return new ResponseBean(HttpStatus.OK.value(), "成功",warningService.semeWarn(year, seam));
        }catch (Exception e){
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR.value(), "错误",null);
        }
    }

    @RequestMapping("/addHelpRecord")
    @LogAnnotation(module = "预警模块", operator = "学期预警详情")
    public ResponseBean addHelpRecord(@RequestBody HelpRecordQuery helpRecordQuery) {
        try{
            return new ResponseBean(HttpStatus.OK.value(), "成功",warningService.addHelpRecord(helpRecordQuery));
        }catch (Exception e){
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR.value(), "错误",null);
        }
    }

    @RequestMapping("/getMyHelpSemeWarn")
    @LogAnnotation(module = "预警模块", operator = "学期预警详情")
    public ResponseBean getMyHelpSemeWarn(@RequestBody WarningQuery warningQuery) {
        try{
            return new ResponseBean(HttpStatus.OK.value(), "成功", warningService.getMyHelpSemeWarn(warningQuery));
        }catch (Exception e){
            return new ResponseBean(HttpStatus.INTERNAL_SERVER_ERROR.value(), "错误",null);
        }
    }
}